
using System;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
namespace Food
{
    [Serializable]
    public class ConsumeFoodComponentModel
    {
        /// <summary>
        /// 所需要的食物
        /// </summary>
        public int foodNeed;
    }
    public class ConsumeFoodComponent : GameMonoBehaviour
    {
        public int FoodNeedPerRound;
        private int dataFood;
        private GameObject hungryGameObject;
        private void Start()
        {
            ConnectSignal(SignalNameDef.CONSUME_FOOD, v => RequireEatFood());
            hungryGameObject = GameObject.Instantiate(FoodManager.Instance.HungryObject, transform);
            hungryGameObject.transform.position = transform.position + Vector3.up * 1.4f;
            hungryGameObject.SetActive(false);
        }
        public void InIt(ConsumeFoodComponentModel model)
        {
            FoodNeedPerRound = model.foodNeed;
        }
        /// <summary>
        /// 发出食物需求
        /// </summary>
        private void RequireEatFood()
        {
            dataFood = FoodNeedPerRound;
            hungryGameObject.SetActive(true);
            FoodManager.Instance.ConsumeFood(gameObject.transform.position, FoodNeedPerRound, this);
        }
        /// <summary>
        /// 结束吃饭
        /// </summary>
        public void FinishEat()
        {
            dataFood--;
            // Debug.Log("吃吃吃  还要吃" + dataFood);
            if (dataFood > 0) return;
            hungryGameObject.SetActive(false);
            //Debug.Log("吃饱了");
        }
        public void HungryDie()
        {
            transform.DOShakePosition(0.5f, 0.2f).OnComplete(() =>
            {
                //Debug.Log("饿死了");
                CardManager.Instance.DelCard(GetComponent<Card>().CardID, true);
            });
        }
    }
}
